package com.chinaedu.oc.context;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.chinaedu.oc.dao.common.CodeListDao;
import com.chinaedu.oc.dao.common.CodeTypeDao;
import com.chinaedu.oc.entity.common.CodeList;
import com.chinaedu.oc.entity.common.CodeType;
import com.chinaedu.oc.service.cache.ProductLineCacheServ;
import com.chinaedu.oc.service.cache.StaticCacheServ;
import com.chinaedu.oc.util.http.HttpRequestException;

/**
 * 获取Spring的Context
 * @Description: TODO
 * @author A18ccms a18ccms_gmail_com 
 * @date 2017年5月26日 下午1:43:26 
 *
 */
public class Context implements ApplicationContextAware{
	
	private static ApplicationContext context;
	private Map<String, String> dataConfig = new HashMap<String, String>();
	public static boolean isCacheProductLine = true;
	
	Logger logger = LoggerFactory.getLogger(getClass());
	
	
	@Autowired
	StaticCacheServ cacheServ;
	
	
	

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
		
	}
	
	/**
	 * 初始化任务
	 * @Description: TODO
	 * @param     
	 * @return void    返回类型 
	 * @throws
	 */
	public void init() {
		logger.info("开始初始化任务...");
		
		//提取proertis参数
		
		try {
			Resource resource = new ClassPathResource("/config.properties");
			Properties props = PropertiesLoaderUtils.loadProperties(resource);
			String service_url = props.getProperty("service_url");
			this.dataConfig.put("service_url", service_url);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		//缓存静态数据
		cacheServ.setCache();
	}

	public static ApplicationContext getContext() {
		return context;
	}

	public static void setContext(ApplicationContext context) {
		Context.context = context;
	}

	public Map<String, String> getDataConfig() {
		return dataConfig;
	}

	public void setDataConfig(Map<String, String> dataConfig) {
		this.dataConfig = dataConfig;
	}
	
	
	
	
}
